import {encodeSearchParams} from "@/common/utils/utils.js";

const PREFIX = '/admin/product'
import request from '@/request/request.js'

/**
 * 获取商品分类
 * @returns {Promise | Promise<unknown> | *}
 */
export const getClassifyList = () => request(`${PREFIX}/classify`)
/**
 * 获取商品列表
 * @returns {*}
 */
export const getProductList = (searchData) => request(`${PREFIX}?${encodeSearchParams(searchData)}`)

/**
 * 添加商品
 * @param data 表单数据
 * @returns {*}
 */
export const addProduct = (data) => request(`${PREFIX}`, data, 'post')

/**
 * 获取商品
 * @returns {*}
 * @param id
 */
export const getProductById = (id) => request(`${PREFIX}/${id}`)

/**
 * 修改商品
 * @param data 表单数据
 * @returns {*}
 */
export const updateProduct = (data) => request(`${PREFIX}`, data, 'put')

/**
 * 删除商品
 * @returns {*}
 * @param id
 */
export const deleteProduct = (id) => request(`${PREFIX}/${id}`, null, 'delete')
